/* 
	1.该文件是用于创建一个为Count组件服务的reducer，reducer的本质就是一个函数
	2.reducer函数会接到两个参数，分别为：之前的状态(preState)，动作对象(action)
*/
import * as constants from "./constants";
import { fromJS } from "immutable";
const initState = fromJS({
  focused: false,
  list: [],
  page: 1,
  totalPage: 1,
  mousein:false,
  isTabFixed:false
}); //初始化状态
export default function countReducer(state = initState, action) {
  // console.log('countReducer@#@#@#');
  //从action对象中获取：type、data
  const { type, data, totalPage ,page,flag} = action;
  //根据type决定如何加工数据
  switch (type) {
    case constants.SEARCH_FOCUS:
      return state.set("focused", true);
    case constants.SEARCH_BLUR:
      return state.set("focused", false);
    case constants.CHANGE_LIST:
      return state.merge({
        list: fromJS(data),
        totalPage: totalPage,
      });
	  case constants.MOUSE_ENTER:
		return state.set("mousein", true);

		case constants.MOUSE_LEAVE:
			return state.set("mousein", false);
	case constants.CHANGE_PAGE:
		return state.set("page",page)
    case constants.TOGGLE_FIXED:
      return state.set("isTabFixed",flag)
    //   return {
    //     focused: true,
    //   };
    // case constants.SEARCH_BLUR:
    //   return {
    //     focused: false,
    //   };
    // case constants.CHANGE_LIST:
    // const newstate = JSON.parse(JSON.stringify(state));
    //   newstate.list=data;
    //   return newstate
    default:
      return state;
  }
}
